'''
测试接口:账号管理/删除
作者:王鑫
'''
import json
import time
from unittest import TestCase

from jsonpath import jsonpath
from parameterized import parameterized

from utils.reader import Reader
from utils.session import Session


class UserSoftDeleteById(TestCase):
    '''
    账号管理删除接口测试类
    作者:王鑫
    '''
    url = 'http://120.53.243.26:8009/api/user/softDeleteById/'
    session = None
    header = None

    @classmethod
    def setUpClass(cls) -> None:
        '''
        获取session对象与token
        :return:
        '''
        cls.session = Session.get_session()
        cls.header = Session.get_header()

    @classmethod
    def tearDownLClass(cls) -> None:
        '''
        关闭session
        :return:
        '''
        cls.session.close()

    @parameterized.expand(Reader.read_excel('wx.xlsx', min_row=28, max_row=32, min_col=9, max_col=12))
    def test_soft_delete_by_id(self, data, expcted_status_code, verify_point, expected_value):
        '''
        执行wx.xlsx文件中第28行至第32行的测试用例
        :param data:
        :param expcted_status_code:
        :param verify_point:
        :param expected_value:
        :return:
        '''
        addr = None
        if data is not None:
            addr = self.url + data
        else:
            addr = self.url

        # 发送请求
        resp = self.session.post(url=addr,headers=self.header)
        json_data = resp.json()

        # 根据验证点提取出实际数据
        real_value = jsonpath(json_data,f'$..{verify_point}')
        if real_value != False:
            real_value = real_value[0]

        # 断言检验响应状态码
        self.assertEqual(200,resp.status_code)

        # 断言检验响应正文的验证点
        if expected_value == 0:
            self.assertEqual(0,real_value)
        else:
            self.assertNotEqual(0,real_value)
